package com.java.basis.io.bio.four;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;

/**
 * @author wangning
 * @create 2022-01-05 21:11
 */
public class ServerRunnableTarget implements Runnable {

	private Socket socket;

	public ServerRunnableTarget(Socket socket) {
		this.socket = socket;
	}
	@Override
	public void run() {
		//处理接收到客户端socket通信需求
		try {
			InputStream is = socket.getInputStream();
			// 把字节输入流包装秤一个缓冲字符输入流
			BufferedReader br = new BufferedReader(new InputStreamReader(is));

			String msg;
			while ((msg = br.readLine()) != null) {
				System.out.println("服务端接收到：" + msg);
			}
		} catch (IOException e) {
//			e.printStackTrace();
			System.out.println("有人下线了");
		}

	}
}
